package com.stsdai.manager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stsdai.manager.pojo.ItemCat;
import com.stsdai.manager.service.ItemCatService;

@Controller
@RequestMapping("item/cat")
public class ItemCatController {

	@Autowired
	private ItemCatService itemCatService;

	// http://127.0.0.1:8080/rest/item/cat/{page}/{rows}
	/**
	 * 分页查询商品类目
	 * 
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping(value = "{page}/{rows}")
	@ResponseBody
	public List<ItemCat> queryItemCatByPage(@PathVariable Integer page, @PathVariable Integer rows) {
		//List<ItemCat> list = this.itemCatService.queryItemCatByPage(page, rows);

		List<ItemCat> list = this.itemCatService.queryByPage(page, rows);
		return list;
	}
	
//	Request URL:http://manager.stsdai.com:8081/rest/item/cat
//	Request Method:GET
	/**
	 * 根据父id查询商品类目
	 * @param parentId
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public List<ItemCat> queryItemCatByParentId(@RequestParam(value = "id", defaultValue = "0") Long parentId) {
		List<ItemCat> list = this.itemCatService.queryItemCatByParentId(parentId);
		return list;
	}
	
	
}
